package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.model.Database;

import siena.jdbc.ddl.DdlGenerator;

public class UseDatabase {

	public static void crear() throws SQLException, ClassNotFoundException{
	DdlGenerator generator = new DdlGenerator();

	// add all your classes
	generator.addTable(User.class);

	// get the Database model
	Database database = generator.getDatabase();

	Platform platform = PlatformFactory.createNewPlatformInstance("mysql");
	Class.forName("com.mysql.jdbc.Driver");
	Connection connection = DriverManager.
	        getConnection("jdbc:mysql://localhost/prueba", "root", "1234");

	// if you want to print the SQL that will be executed
	String sql = platform.getAlterTablesSql(connection, database);
	System.out.println(sql);

	// this will perform the database changes
	platform.alterTables(connection, database, true);

	connection.close();
	}
}
